import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {FormValidatorService} from "great-ngform";

@Component({
  selector: 'app-form-form-validator',
  templateUrl: './form-validator.component.html',
})
export class FormFormValidatorComponent implements OnInit {
  formGrop: FormGroup;
  constructor(
    private fb: FormBuilder,
    private formValidatorService: FormValidatorService
  ) {
    this.formGrop = this.fb.group({
      username: ['', [this.formValidatorService.required({errorMsg:'用户名不能为空！'})]],
      email: ['', [this.formValidatorService.email({
        errorMsg:'邮箱格式不正确！'
      }), Validators.required]],
      password: ['', [Validators.required]],
      confirm: ['', ],
      comment: ['', [Validators.required]]
    });
  }

  ngOnInit(): void {
  }

  submitForm(){
    this.formValidatorService.checkForm(this.formGrop);
  }
}
